#宿主机:
sudo ln -s /pubx/llvm-project/analyze_clang_by_gdb/8cc-malloc-analyze /pubx/8cc-malloc-analyze
sudo docker exec -it taintgrind_CppBuildEnv bash

#以下命令在docker 实例的bash提示符下执行:

cd /pubx/8cc-malloc-analyze/

#1. 确定分配内存用的是 malloc 、 new 哪个?    结论： 8cc分配内存用的是malloc
valgrind --trace-children=yes    --keep-debuginfo=yes  --allow-mismatched-debuginfo=yes  --read-inline-info=yes   --read-var-info=yes    --tool=dhat /pubx/8cc/8cc -c  mini_main.c -o  mini_main.o

#2. gdb打印大尺寸malloc入参
gdb -x malloc_print.gs --args /pubx/8cc/8cc -c  mini_main.c
wc -l malloc_print.log
# 108 malloc_print.log


#补充：步骤2 之前 需要加 glibc的源码路径
echo """
# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源，不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
""" > /etc/apt/sources.list

apt update
cd /pubx/8cc-malloc-analyze/
apt source  libc6-dev
#目录/pubx/8cc-malloc-analyze/下多出:   glibc-2.27/     glibc_2.27-3ubuntu1.6.debian.tar.xz    glibc_2.27-3ubuntu1.6.dsc  glibc_2.27.orig.tar.xz 
#其中目录 /pubx/8cc-malloc-analyze/glibc-2.27/malloc/ 就是 malloc函数所在目录